<script>
  import {
    mapGetters,
    mapActions,
    mapMutations
  } from 'vuex'
  import {
    uniAdminCacheKey
  } from './store/constants.js'
  import config from '@/admin.config.js'

  export default {
    computed: {
      ...mapGetters({
        isTokenValid: 'user/isTokenValid'
      })
    },
    methods: {
      ...mapMutations('app', ['SET_THEME']),
      ...mapActions({
        configInit: "config/init",
        userInit: "user/init"
      })
    },
    onPageNotFound(msg) {
      uni.redirectTo({
        url: config.error.url
      })
    },
    onLaunch: async function() {

      console.log('App Launch')

      // theme
      this.SET_THEME(uni.getStorageSync(uniAdminCacheKey.theme) || 'default')

      this.userInit().catch(_ => {
        uni.redirectTo({
          url: config.login.url
        })
      });
    },
    onShow: function() {
      this.configInit()
      console.log('App Show')
    },
    onHide: function() {
      console.log('App Hide')
    }
  }
</script>

<style lang="scss">
  @import '@/common/uni.css';
  @import '@/common/uni-icons.css';
  @import '@/common/admin-icons.css';
  @import '@/common/theme.scss';

  @import '@/unify.scss';
  
  @media screen and (max-width: 500px) {
    page {
      margin-top: 60px;
    }
  }
</style>